package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.ShortVideo;
import com.ruoyi.cms.service.IShortVideoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短视频管理Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/cms/short")
public class ShortVideoController extends BaseController
{
    @Autowired
    private IShortVideoService shortVideoService;

    /**
     * 查询短视频列表
     */
    @PreAuthorize("@ss.hasPermi('cms:short:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShortVideo shortVideo)
    {
        startPage();
        List<ShortVideo> list = shortVideoService.selectShortVideoList(shortVideo);
        return getDataTable(list);
    }

    /**
     * 获取短视频详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:short:query')")
    @GetMapping(value = "/{videoId}")
    public AjaxResult getInfo(@PathVariable("videoId") Long videoId)
    {
        return AjaxResult.success(shortVideoService.selectShortVideoById(videoId));
    }

    /**
     * 新增短视频
     */
    @PreAuthorize("@ss.hasPermi('cms:short:add')")
    @Log(title = "短视频管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShortVideo shortVideo)
    {
        return toAjax(shortVideoService.insertShortVideo(shortVideo));
    }

    /**
     * 修改短视频
     */
    @PreAuthorize("@ss.hasPermi('cms:short:edit')")
    @Log(title = "短视频管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShortVideo shortVideo)
    {
        return toAjax(shortVideoService.updateShortVideo(shortVideo));
    }

    /**
     * 删除短视频
     */
    @PreAuthorize("@ss.hasPermi('cms:short:remove')")
    @Log(title = "短视频管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{videoIds}")
    public AjaxResult remove(@PathVariable Long[] videoIds)
    {
        return toAjax(shortVideoService.deleteShortVideoByIds(videoIds));
    }

    /**
     * 审核短视频
     */
    @PreAuthorize("@ss.hasPermi('cms:short:audit')")
    @Log(title = "短视频审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody ShortVideo shortVideo)
    {
        return toAjax(shortVideoService.auditShortVideo(shortVideo));
    }

    /**
     * 批量审核通过
     */
    @PreAuthorize("@ss.hasPermi('cms:short:audit')")
    @Log(title = "批量审核通过", businessType = BusinessType.UPDATE)
    @PutMapping("/approve/{videoIds}")
    public AjaxResult approve(@PathVariable Long[] videoIds)
    {
        return toAjax(shortVideoService.approveVideos(videoIds));
    }

    /**
     * 批量审核拒绝
     */
    @PreAuthorize("@ss.hasPermi('cms:short:audit')")
    @Log(title = "批量审核拒绝", businessType = BusinessType.UPDATE)
    @PutMapping("/reject/{videoIds}")
    public AjaxResult reject(@PathVariable Long[] videoIds)
    {
        return toAjax(shortVideoService.rejectVideos(videoIds));
    }

    /**
     * 获取审核通过的短视频列表（前台使用）
     */
    @GetMapping("/approved")
    public AjaxResult getApprovedVideos()
    {
        return AjaxResult.success(shortVideoService.selectApprovedVideos());
    }

    /**
     * 导出短视频列表
     */
    @PreAuthorize("@ss.hasPermi('cms:short:export')")
    @Log(title = "短视频管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShortVideo shortVideo)
    {
        List<ShortVideo> list = shortVideoService.selectShortVideoList(shortVideo);
        ExcelUtil<ShortVideo> util = new ExcelUtil<ShortVideo>(ShortVideo.class);
        util.exportExcel(response, list, "短视频数据");
    }
}